home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / cli / bangtools.lha / src / poke.c < prev   
C/C++ Source or Header  |  1995-01-15  |  3KB  |  90 lines

  1. /* poke - write a value directly into memory
  2.  *
  3.  * Copyright (C) 1994 by Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose and without fee is hereby granted, provided
  7.  * that the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation.  This software is provided "as is" without express or
  10.  * implied warranty.
  11.  *
  12.  * V1.0: 27/Nov/94 first version
  13.  */
  14. #define THIS_PROGRAM    "poke"
  15. #define THIS_VERSION    "1.0"
  16.  
  17. #include <exec/types.h>
  18. #include <exec/libraries.h>
  19. #include <dos/dos.h>
  20. #include <dos/rdargs.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24. #define SysBase_DECLARED
  25. #include <proto/exec.h>
  26. #include <proto/dos.h>
  27. #include <proto/utility.h>
  28.  
  29. extern struct Library *SysBase;
  30.  
  31. static const char amiga_version[] = "\0$VER: " THIS_PROGRAM " " THIS_VERSION " (" __COMMODORE_DATE__ ")";
  32.  
  33. const char Template[] = "ADDR/A,VALUE/A,B=BYTE/S,S=SHORT=W=WORD/S,L=LONG/S";
  34. __aligned struct {
  35.     STRPTR  addr;
  36.     STRPTR  value;
  37.     LONG    isbyte, isword, islong;
  38. } Args;
  39.  
  40. void
  41. _main()
  42. {
  43.     struct RDArgs *rdargs;
  44.     APTR addr;
  45.     ULONG val;
  46.     LONG rc = RETURN_OK;
  47.  
  48.     if( SysBase->lib_Version < 37 ) {
  49.         #define MESSAGE "requires AmigaOS 2.04 or higher\n"
  50.         Write(Output(), MESSAGE, sizeof(MESSAGE)-1);
  51.         _exit(RETURN_FAIL);
  52.         #undef MESSAGE
  53.     }
  54.  
  55.     if( rdargs = ReadArgs(Template, (LONG *)&Args, NULL) ) {
  56.         int used = 0;
  57.         if( Args.isbyte )   used++;
  58.         if( Args.isword )   used++;
  59.         if( Args.islong )   used++;
  60.         if( used > 1 ) {
  61.             PutStr("only one type specifier allowed\n");
  62.             rc = RETURN_ERROR;
  63.         }
  64.         else {
  65.             char *endp1, *endp2;
  66.             addr = (APTR)strtoul(Args.addr, &endp1, 0);
  67.             val  = strtoul(Args.value, &endp2, 0);
  68.             if( *endp1 != '\0' || *endp2 != '\0' ) {
  69.                 PutStr("invalid address or value\n");
  70.                 rc = RETURN_ERROR;
  71.             }
  72.             else
  73.             if( Args.islong )
  74.                 *(ULONG *)addr = val;
  75.             else
  76.             if( Args.isword )
  77.                 *(USHORT *)addr = (SHORT)val;
  78.             else
  79.                 *(UBYTE *)addr = (BYTE)val;
  80.         }
  81.         FreeArgs(rdargs);
  82.     }
  83.     else {
  84.         PutStr("required argument missing\n");
  85.         rc = RETURN_ERROR;
  86.     }
  87.     _exit((int)rc);
  88. }
  89.  
  90.